const InfoKey = 'smart_mall_user_info'
const SearchKey = 'smart_mall_search_list'

// 存储用户信息
export const setUserInfo = (info) => {
  localStorage.setItem(InfoKey, JSON.stringify(info))
}

// 获取用户信息
export const getUserInfo = () => {
  const defaultInfo = {
    token: '',
    userId: ''
  }
  const info = JSON.parse(localStorage.getItem(InfoKey))
  return info || defaultInfo
}

// 移除用户信息
export const removeUserInfo = () => {
  localStorage.removeItem(InfoKey)
}

// search页面
// 储存搜索历史
export const setSearchList = (list) => {
  localStorage.setItem(SearchKey, JSON.stringify(list))
}
// 获取搜索历史
export const getSearchList = () => {
  const list = localStorage.getItem(SearchKey)
  return list ? JSON.parse(list) : []
}
